package com.cennavi.minemapdemo.util;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.os.Build;

public class BitmapUtil {

	public static Bitmap drawableToBitmap(Context context, int vectorDrawableId) {
		Bitmap bitmap = null;
		if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
			Drawable vectorDrawable = context.getDrawable(vectorDrawableId);
			if (vectorDrawable != null) {
				bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(),
						vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_4444);
				Canvas canvas = new Canvas(bitmap);
				vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
				vectorDrawable.draw(canvas);
			}
		} else {
			bitmap = BitmapFactory.decodeResource(context.getResources(), vectorDrawableId);
		}
		return bitmap;
	}
}
